package com.javasea.scene.code;

/**
 *@ClassName Demo
 *@Description TODO
 *@Author longxiaonan@163.com
 *@Date 2022/3/5 0005 10:23
 */
public class Demo {
    public static void main(String[] args) {
//        long value = 4928;  // 01A0
//        long value = 9834495; // ZZZZ
//        int codeLen = 4;
//        String s = generateCodeByValue(value, codeLen);
//        System.out.println(s);
        int value = getValueByCode("ZZZZZ");
        System.out.println(value);
    }

    private static String getCodeByValue(long value, int codeLen) {
        int baseCodeCount = CodeMap.map1.values().size();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < codeLen; i++) {
            long codeChar = value % baseCodeCount;
            value = value / baseCodeCount;
            sb.append(CodeMap.map1.get(String.valueOf(codeChar)));
        }
        String s = sb.reverse().toString();
        return s;
    }

    private static int getValueByCode(String code){
        int baseCodeCount = CodeMap.map1.values().size();
        int codeLen = code.length();
        double sum = 0;
        for (int i = 0; i < codeLen; i++) {
            char c = code.charAt(i);
            Integer baseValue = CodeMap.map2.get(c);
            double pow = Math.pow(baseCodeCount, codeLen - 1 - i);
            sum += baseValue * pow;
        }
        return (int)sum;
    }

    private static int getMaxValue(){
        int maxValue = getValueByCode("ZZZZ");
        return maxValue;
    }

    private static int getMaxValue4Len(){
        int maxValue = getValueByCode("ZZZZ");
        return maxValue;
    }

    private static int getMaxValue5Len(){
        int maxValue = getValueByCode("ZZZZZ");
        return maxValue;
    }

    private static int getMaxValue6Len(){
        int maxValue = getValueByCode("ZZZZZZ");
        return maxValue;
    }

}
